/*
 * Copyright (C), 2013-2015, 上海汽车集团股份有限公司
 * FileName: AuthInterceptor.java
 * Author:   tantun
 * Date:     2015年3月24日 上午9:17:22
 * Description: //模块目的、功能描述      
 * History: //修改记录
 * <author>      <time>      <version>    <desc>
 * 修改人姓名             修改时间            版本号                  描述
 */
package com.hissy.common;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.RedirectView;

/**
 * 拦截器
 *
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
public class AuthInterceptor implements HandlerInterceptor {
    private static final Logger LOGGER = LoggerFactory.getLogger(AuthInterceptor.class);

    private static String resetTime;

    @Autowired
    private MultiDomUrl jscssUrl;

    static {
        resetTime = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date());
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object object,
                                Exception exception) {
        LOGGER.debug("end reponse");
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object object,
                           ModelAndView modelAndView) {
    }

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object object) {

        LOGGER.debug(request.getParameterMap().toString());
        // 配置菜单标签
        request.setAttribute("jscssUrl", jscssUrl);
        request.setAttribute("resetTime", resetTime);
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://" + request.getServerName() + ":"
            + request.getServerPort() + path + "/";
        request.setAttribute("cxjBasePath", basePath);
        return true;
    }
}
